package org.neurone.session.impl;

import javax.servlet.http.HttpSession;

import org.neurone.session.SessionServer;
import org.neurone.context.SessionConst;



public class SessionServerLocal implements SessionServer{
	private HttpSession httpSession;
	
	@Override
	public HttpSession getSession() {
		return this.httpSession;
	}

	@Override
	public String getSessionID() {
		return  httpSession.getId();
		
	}

	@Override
	public String getSessionUserID() {
		if(this.httpSession!=null&&this.httpSession.getAttribute(SessionConst.SESSION_USER_ID)!=null){
			return  this.httpSession.getAttribute(SessionConst.SESSION_USER_ID).toString();
		}
		return null;
	}
	@Override
	public String getSessionKey() {
		if(this.httpSession!=null&&this.httpSession.getAttribute(SessionConst.SESSION_BROWSER_KEY)!=null){
			return  this.httpSession.getAttribute(SessionConst.SESSION_BROWSER_KEY).toString();
		}
		return null;
	}
	@Override
	public String getKey() {
		if(this.httpSession!=null&&this.httpSession.getAttribute(SessionConst.SESSION_KEY)!=null){
			return  this.httpSession.getAttribute(SessionConst.SESSION_KEY).toString();
		}
		return null;
	}	
	
	@Override
	public void logoutSession() {
		this.httpSession.removeAttribute(SessionConst.SESSION_USER_ID);	
		this.httpSession.removeAttribute(SessionConst.SESSION_KEY);			
		this.httpSession.removeAttribute(SessionConst.SESSION_BROWSER_KEY);
	}

	@Override
	public void registerSession(String key, String userID) {
		
		this.httpSession.setAttribute(SessionConst.SESSION_KEY, userID);
		this.httpSession.setAttribute(SessionConst.SESSION_USER_ID, userID);	
	}
	
	@Override
	public void registerSessionKey(String sessionKey) {
		
		this.httpSession.setAttribute(SessionConst.SESSION_BROWSER_KEY, sessionKey);
	}

	public SessionServerLocal(HttpSession httpSession)
	{
		this.httpSession = httpSession;
	}
	
	public SessionServerLocal()
	{
		
	}
}
